/**
 * 验证input[type='date']
 * @param name
 * @returns {boolean}
 */
function checkDate(name) {
    if(name.val() == ""){
        name.prev().css("color","red");
        return false;
    }
    name.prev().css("color","black");
    return true;
}

/**
 * 验证input[type='checkbox']
 * @param name
 * @returns {boolean}
 */
function checkCheckBox(name) {
    for(var i = 0;i < name.length;i++){
        if(name[i].checked){
            name[0].previousElementSibling.style.color = "black";
            return true;
        }
    }
    name[0].previousElementSibling.style.color = "red";
    return false;
}

/**
 * 验证input[type='select']
 * @param name
 * @param reg
 * @param title
 * @returns {boolean}
 */
function checkSelect(name,reg,title) {
    var opt = $("#"+name+" option:selected");
    var regObj = new RegExp(reg);
    if(opt.val() == null || opt.val() == ""){
        opt.parent().prev().css("color","red");
        return false;
    }else if(!regObj.test(opt.val())){
        opt.parent().prev().css("color","black");
        return true;
    }else{
        opt.parent().prev().css("color","red");
        return false;
    }
}

/**
 * 验证input[type='text']
 * @param name
 * @param reg
 * @param title
 * @returns {boolean}
 */
function checkText(name,reg,title) {
    var regObj = new RegExp(reg);
    if(name.val() == null || name.val() == ""){
        name.prev().css("color","red");
        return false;
    }else if(regObj.test(name.val())){
        name.prev().css("color","black");
        return true;
    }else{
        name.prev().css("color","red");
        return false;
    }
}

/**
 * 表单验证
 * @returns {boolean}
 */
function res() {
    return checkText(name1,"^[\u4e00-\u9fa5]{2,}$","只能输入汉字")
        && checkText(nickname,"^.{3,6}?$","长度为3-6位")
        && checkText(eglishname,"^[a-z| ]{3,}$","长度大于3位的小写字母")
        && checkText(age,"^[0-9]{1,2}$","请输入正确的年龄")
        && checkText(place,"^[\u4e00-\u9fa5]{2,}$","请输入户籍")
        && checkSelect("minzu","请选择：","请选择：")
        && checkSelect("sheng","请选择：","请选择：")
        && checkCheckBox(hobby)
        && checkDate(date);
}